﻿using NHibernate.Criterion;
using OVS.Core;
using OVS.Domain;
using OVS.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OVS.webUI.Controllers
{
    public class VotingController : Controller
    {
        // GET: Voting
        public ActionResult Index()
        {
            return View();
        }

        //投票
        public JsonResult TicketAdd(int MpiId,int Type)
        {
            MatchPKInfo mpi = Container.Instance.Resolve<IMatchPKInfoService>().Get(MpiId);
            if (Type == 1)
            {
                mpi.FirstTickCount++;
            }else if(Type==2)
            {
                mpi.SecondTickCount++;
            }
            try
            {
                Container.Instance.Resolve<IMatchPKInfoService>().Update(mpi);
            }
            catch
            {
                return Json(0,JsonRequestBehavior.AllowGet);
            }
            return Json(1,JsonRequestBehavior.AllowGet);
        }

        //获取当前投票选手信息
        public JsonResult GetMatchPKInfo()
        {
            IList<ICriterion> queryConditions = new List<ICriterion>();
            queryConditions.Add(Expression.Eq("BattleFlag", 1));

            IList<MatchPKInfo> mpi = Container.Instance.Resolve<IMatchPKInfoService>().Find(queryConditions);
            try
            {
                return Json(mpi[0], JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json(0, JsonRequestBehavior.AllowGet);
            }
        }
    }
}